package 博客管理系统;

import java.sql.*;
import javax.swing.JFrame;
import java.awt.event .*;
import javax.swing .*;

class Update_bk extends JPanel implements ActionListener{
    JLabel JL = new JLabel("修改用户信息", JLabel.CENTER);
    JLabel id = new JLabel("请输入您要修改的用户ID");
    JTextField id1 = new JTextField();
    JLabel massage = new JLabel("请输入您要修改的密码");
    JTextField Massage = new JTextField();

    JTextField jt=new JTextField(10);
    JButton Get = new JButton("修改");
    JButton Reset = new JButton("重置");
    JButton Exit = new JButton("退出");
    String sql = "";

    public static void main(String[] args) {
        new Update_user();
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==Get){
            Statement stm=null;
            Connection con;
            Statement st;
            ResultSet rs;
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=BlogSystemLD";
            String userName="sa";
            String userPwd="123";
            String sql="select * from BlogContent";
            try{
                con = DriverManager.getConnection(dbURL, userName, userPwd);
                st = con.createStatement();
                rs = st.executeQuery(sql);
                stm=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
                sql="update id set "+Massage.getText()+"='";
                int n=stm.executeUpdate(sql);
                if(n!=0)JOptionPane.showMessageDialog(null,"修改成功！");
                else JOptionPane.showMessageDialog(null,"修改失败！");
            }catch(Exception er){
                er.printStackTrace();
            }
        }
        if(e.getSource()==Reset){
            id1.setText(null);
            Massage.setText(null);

        }
        if(e.getSource()==Exit) {
            this.setVisible(false);
        }
    }
}